package com.link.server.ws.handle.impl;

import com.link.common.packet.RequestOperate;
import com.link.common.packet.ResponseOperate;
import com.link.common.packet.resp.SimplePacketResp;
import com.link.common.util.BinaryUtils;
import com.link.database.entity.DBAccount;
import com.link.database.service.DBAccountService;
import com.link.server.ws.handle.HandleComponent;
import com.link.server.ws.handle.Handler;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import jakarta.annotation.Resource;

@HandleComponent(RequestOperate.REAL_NAME_AUTHENTICATION)

public class RealNameAuthenticationHandle implements Handler {
    @Resource
    private DBAccountService dbAccountService;
    @Override
    public   void invoke(RequestOperate operate, ByteBuf packet, ChannelHandlerContext ctx) throws  Exception{
         //TODO 调用身份证验证接口
        DBAccount account =  ctx.channel().attr(Handler.ACCOUNT_KEY).get();
        var name= BinaryUtils.readString(packet);
        var idCard= BinaryUtils.readString(packet);

        account.setName(name);
        account.setIdNumber(idCard);
        account.setAdult(true);

        dbAccountService.update(account);

        this.send(ctx,SimplePacketResp.response(ctx,ResponseOperate.REAL_NAME_AUTHENTICATION, (short) 200));


    }
}
